﻿using System;
using System.IO;
using Manager;
using UnityEngine;

namespace Studio
{
	// Token: 0x0200052E RID: 1326
	public class BGMCtrl
	{
		// Token: 0x170003FE RID: 1022
		// (get) Token: 0x060021B8 RID: 8632 RVA: 0x000CD9C8 File Offset: 0x000CBBC8
		// (set) Token: 0x060021B9 RID: 8633 RVA: 0x000CD9D0 File Offset: 0x000CBBD0
		public BGMCtrl.Repeat repeat
		{
			get
			{
				return this.m_Repeat;
			}
			set
			{
				if (Utility.SetStruct<BGMCtrl.Repeat>(ref this.m_Repeat, value) && this.audioSource)
				{
					this.audioSource.loop = (this.repeat == BGMCtrl.Repeat.All);
				}
			}
		}

		// Token: 0x170003FF RID: 1023
		// (get) Token: 0x060021BA RID: 8634 RVA: 0x000CDA08 File Offset: 0x000CBC08
		// (set) Token: 0x060021BB RID: 8635 RVA: 0x000CDA10 File Offset: 0x000CBC10
		public int no
		{
			get
			{
				return this.m_No;
			}
			set
			{
				if (this.m_No != value)
				{
					this.Play(value);
				}
			}
		}

		// Token: 0x17000400 RID: 1024
		// (get) Token: 0x060021BC RID: 8636 RVA: 0x000CDA28 File Offset: 0x000CBC28
		// (set) Token: 0x060021BD RID: 8637 RVA: 0x000CDA30 File Offset: 0x000CBC30
		public bool play
		{
			get
			{
				return this.m_Play;
			}
			set
			{
				if (Utility.SetStruct<bool>(ref this.m_Play, value))
				{
					if (this.m_Play)
					{
						this.Play();
					}
					else
					{
						this.Stop();
					}
				}
			}
		}

		// Token: 0x17000401 RID: 1025
		// (get) Token: 0x060021BE RID: 8638 RVA: 0x000CDA60 File Offset: 0x000CBC60
		// (set) Token: 0x060021BF RID: 8639 RVA: 0x000CDA68 File Offset: 0x000CBC68
		public bool isPause { get; private set; }

		// Token: 0x060021C0 RID: 8640 RVA: 0x000CDA74 File Offset: 0x000CBC74
		public void Play()
		{
			if (this.isPause)
			{
				this.isPause = false;
				Singleton<Manager.Sound>.Instance.PlayBGM(0f);
			}
			else
			{
				this.m_Play = true;
				this.Play(this.m_No);
			}
		}

		// Token: 0x060021C1 RID: 8641 RVA: 0x000CDAB0 File Offset: 0x000CBCB0
		public void Play(int _no)
		{
			this.m_No = _no;
			if (!this.m_Play)
			{
				return;
			}
			Info.LoadCommonInfo loadCommonInfo = null;
			if (!Singleton<Info>.Instance.dicBGMLoadInfo.TryGetValue(this.m_No, out loadCommonInfo))
			{
				return;
			}
			if (Singleton<Studio>.Instance.outsideSoundCtrl.play)
			{
				Singleton<Studio>.Instance.outsideSoundCtrl.Stop();
			}
			Transform transform = Singleton<Manager.Sound>.Instance.Play(Manager.Sound.Type.BGM, loadCommonInfo.bundlePath, loadCommonInfo.fileName, 0f, 0f, true, true, -1, true);
			if (transform == null)
			{
				return;
			}
			this.audioSource = transform.GetComponent<AudioSource>();
			this.audioSource.loop = (this.repeat == BGMCtrl.Repeat.All);
			this.isPause = false;
		}

		// Token: 0x060021C2 RID: 8642 RVA: 0x000CDB6C File Offset: 0x000CBD6C
		public void Stop()
		{
			this.m_Play = false;
			this.isPause = false;
			Singleton<Manager.Sound>.Instance.StopBGM(0f);
		}

		// Token: 0x060021C3 RID: 8643 RVA: 0x000CDB8C File Offset: 0x000CBD8C
		public void Pause()
		{
			if (!this.m_Play)
			{
				return;
			}
			this.isPause = true;
			Singleton<Manager.Sound>.Instance.PauseBGM();
		}

		// Token: 0x060021C4 RID: 8644 RVA: 0x000CDBAC File Offset: 0x000CBDAC
		public void Save(BinaryWriter _writer, Version _version)
		{
			_writer.Write((int)this.m_Repeat);
			_writer.Write(this.m_No);
			_writer.Write(this.m_Play);
		}

		// Token: 0x060021C5 RID: 8645 RVA: 0x000CDBD4 File Offset: 0x000CBDD4
		public void Load(BinaryReader _reader, Version _version)
		{
			this.m_Repeat = (BGMCtrl.Repeat)_reader.ReadInt32();
			this.m_No = _reader.ReadInt32();
			this.m_Play = _reader.ReadBoolean();
		}

		// Token: 0x0400231B RID: 8987
		private BGMCtrl.Repeat m_Repeat = BGMCtrl.Repeat.All;

		// Token: 0x0400231C RID: 8988
		private int m_No;

		// Token: 0x0400231D RID: 8989
		private bool m_Play;

		// Token: 0x0400231F RID: 8991
		private AudioSource audioSource;

		// Token: 0x0200052F RID: 1327
		public enum Repeat
		{
			// Token: 0x04002321 RID: 8993
			None,
			// Token: 0x04002322 RID: 8994
			All
		}
	}
}
